package duo_tai;

public class TestBasiccTwo {
    public static void main(String[] args) {
        Employee employee = new Employee();
        employee.name="jack";
        Vechile myVehicle = employee.Buy(150);

        if(myVehicle!=null){
            employee.goHome(myVehicle);
        }else{
            System.out.println("买不成");
        }
    }
}
class Employee {
    String name;

    //父类类型作为方法的形参，实现多态
    public void goHome(Vechile vechile) {//Vechiche ve =new Biycle();
        System.out.println(name + "正在乘坐");
        vechile.run();
    }
        //新的 父类作为方法返回值实现多态，使方法可以返回不同子类对象
        public Vechile Buy ( int money){
            Vechile veh = null;//方法返回值
            if (money > 0 && money < 30) {
                //买一俩公交车
                Bus bus = new Bus();
                bus.type = "公交车";
                bus.speed = 400;
                bus.price = 100000.3;
                bus.setNum = 20;
                veh = bus;
            } else if (money >= 30) {
                //买一俩小汽车
                Car car = new Car();
                car.type = "小汽车";
                car.speed = 120;
                car.price = 3000.0;
                car.brand = "BMW";
                veh = car;
            } else {
                //买一辆自行车
                Biycle biycle = new Biycle();
                biycle.type = "自行车";
                biycle.speed = 200;
                biycle.price = 200.0;
                biycle.color = "红色";
                veh = biycle;
            }
            return veh;
        }
    }

    class Vechile {
        String type;
        int speed;
        double price;

        public void run() {
            System.out.println("父类一俩价值" + price + "钱的" + type + "正在以" + speed + "/速度前进");
        }
    }

    class Car extends Vechile {
        String brand;

        public void run() {
            System.out.println("子类一俩价值" + price + "钱的" + type + "正在以" + speed + "/速度前进");
        }
    }

    class Bus extends Vechile {
        int setNum;

        public void run(Bus bus) {
            System.out.println("一俩价值" + price + "钱的" + type + "正在以" + speed + "/速度前进");
        }
    }

    class Biycle extends Vechile {
        String color;

        public void run(Biycle biycle) {
            System.out.println("一俩价值" + price + "钱的" + type + "正在以" + speed + "/速度前进");
        }
    }

